package com.example.aixiangshou.runninggame;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;

import com.x_memteor.base_master.application.MyApplication;
import com.x_memteor.base_master.base.BaseActivity;
import com.x_memteor.base_master.utils.ToastUtils;
import com.x_memteor.base_master.utils.Util;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class ChooseItemActivity extends BaseActivity{

    @BindView(R.id.tv_choose_item)
    TextView tvChooseItem;
    @BindView(R.id.edit_game)
    EditText editGame;
    @BindView(R.id.edit_turn)
    EditText editTurn;
    @BindView(R.id.edit_points)
    EditText editPoints;
    @BindView(R.id.btn_back)
    Button btnBack;
    @BindView(R.id.btn_next)
    Button btnNext;
    @BindView(R.id.spinner)
    Spinner spinner;
    @BindView(R.id.spinner2)
    Spinner spinner2;
    @BindView(R.id.spinner3)
    Spinner spinner3;
    List<String> data_list = new ArrayList<String>();
    List<String> data_list2 = new ArrayList<String>();
    List<String> data_list3 = new ArrayList<String>();

    int gameDuration = 1;
    int turnDuration = 1;
    int pointsToWin = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void initRootView() {
        setContentView(R.layout.activity_choose_item);
    }

    @Override
    public void initView() {
        Util.setText(ChooseItemActivity.this, tvChooseItem);
    }

    @Override
    public void initData() {
        //数据
        for (int i = 1; i <= 49; i++){
            data_list.add(i + "");
        }

        //数据
        for (int i = 1; i <= 31; i++){
            data_list2.add(i + "");
        }

        for (int i = 1; i <= 11 ; i++) {
            data_list3.add(i + "");
        }
        //适配器
        simpleArrayAdapter arrAdapter = new simpleArrayAdapter<String>(this, R.layout.spanner_item, data_list);
        //设置样式
        arrAdapter.setDropDownViewResource(R.layout.spanner_item);

        //适配器
        simpleArrayAdapter arrAdapter2 = new simpleArrayAdapter<String>(this, R.layout.spanner_item, data_list2);
        //设置样式
        arrAdapter2.setDropDownViewResource(R.layout.spanner_item);

        //适配器
        simpleArrayAdapter arrAdapter3 = new simpleArrayAdapter<String>(this, R.layout.spanner_item, data_list3);
        //设置样式
        arrAdapter3.setDropDownViewResource(R.layout.spanner_item);

        //加载适配器
        spinner.setAdapter(arrAdapter);
        spinner.setSelection(0, true);
        spinner2.setAdapter(arrAdapter2);
        spinner2.setSelection(0, true);
        spinner3.setAdapter(arrAdapter3);
        spinner3.setSelection(0, true);
    }

    @Override
    public void initListener() {
        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                gameDuration = Integer.parseInt(data_list.get(position));
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
        spinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                turnDuration = Integer.parseInt(data_list.get(position));

            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
        spinner3.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                pointsToWin = Integer.parseInt(data_list.get(position));

            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
    }

    @OnClick({R.id.btn_back, R.id.btn_next})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_back:
                finish();
                break;
            case R.id.btn_next:
                MyApplication.getInstance().getGameBean().setGameDuration(gameDuration);
                MyApplication.getInstance().getGameBean().setTurnuration(turnDuration);
                MyApplication.getInstance().getGameBean().setPointsToWin(pointsToWin);
                startActivity(new Intent(ChooseItemActivity.this, AddOptionActivity.class));
                break;
        }
    }
}
